RecordStatus and DefaultCursorDriver Properties Example
This example uses the RecordStatus and DefaultCursorDriver properties to show how changes to a local Recordset are tracked during batch updating. The RecordStatusOutput function is required for this procedure to run.
Sub RecordStatusX()
Dim wrkMain As Workspace
Dim conMain As Connection
Dim rstTemp As Recordset
Set wrkMain = CreateWorkspace("ODBCWorkspace", _
"admin", "", dbUseODBC)
' This DefaultCursorDriver setting is required for
' batch updating.
wrkMain.DefaultCursorDriver = dbUseClientBatchCursor
' Note: The DSN referenced below must be configured to
' use Microsoft Windows NT Authentication Mode to
' authorize user access to the Microsoft SQL Server.
Set conMain = wrkMain.OpenConnection("Publishers", _
dbDriverNoPrompt, False, _
"ODBC;DATABASE=pubs;DSN=Publishers")
' The following locking argument is required for
' batch updating.
Set rstTemp = conMain.OpenRecordset( _
"SELECT * FROM authors", dbOpenDynaset, 0, _
dbOptimisticBatch)
With rstTemp
.MoveFirst
Debug.Print "Original record: " & !au_lname
Debug.Print , RecordStatusOutput2(.RecordStatus)
.Edit
!au_lname = "Bowen"
.Update
Debug.Print "Edited record: " & !au_lname
Debug.Print , RecordStatusOutput2(.RecordStatus)
.AddNew
!au_lname = "NewName"
.Update
Debug.Print "New record: " & !au_lname
Debug.Print , RecordStatusOutput2(.RecordStatus)
.Delete
Debug.Print "Deleted record: " & !au_lname
Debug.Print , RecordStatusOutput2(.RecordStatus)
' Close the local recordset without updating the
' data on the server.
.Close
End With
conMain.Close
wrkMain.Close
End Sub
Function RecordStatusOutput(lngTemp As Long) As String
Dim strTemp As String
strTemp = ""
' Construct an output string based on the RecordStatus
' value.
If lngTemp = dbRecordUnmodified Then _
strTemp = "[dbRecordUnmodified]"
If lngTemp = dbRecordModified Then _
strTemp = "[dbRecordModified]"
If lngTemp = dbRecordNew Then _
strTemp = "[dbRecordNew]"
If lngTemp = dbRecordDeleted Then _
strTemp = "[dbRecordDeleted]"
If lngTemp = dbRecordDBDeleted Then _
strTemp = "[dbRecordDBDeleted]"
RecordStatusOutput = strTemp
End Function